package megaezgo

import (
	//"wxsdk/utils/mapstruct"
	"github.com/astaxie/beego"
)

type RefundRsp struct {
	SYS_REFUND_NO string `json:"SYS_REFUND_NO"`
}
/*
{"Header":{"StatusCode":"9997","StatusDesc":"交易處理中PROCESSING","ResponseTime":"2019-03-22 15:31:21"},"Data":{"DataValue":"{\"SYS_REFUND_NO\":\"2019032200000639\"}"}} 
*/
func Refunds(apiStoreId,terminalIp,apiStorePw,refundNo,orderId,sysOrderNo,deviceInfo,
             currency string,orderAmount,RefundAmount int,privateKey []byte)(rsp *RefundRsp, err error){
	
	type RefundReq struct {
		StoreRefundNo string `json:"store_refund_no"`
		StoreOrderNo  string `json:"store_order_no"`
		//SysOrderNo    string `json:"sys_order_no"`
		DeviceInfo    string `json:"device_info"`
		OrderAmount   int    `json:"order_amount"`
		RefundAmount  int    `json:"refund_amount"`
		Currency      string `json:"currency"`
	}
	req := new(RefundReq)
	req.StoreRefundNo = refundNo
	req.StoreOrderNo = orderId
	//req.SysOrderNo = sysOrderNo
	req.DeviceInfo = deviceInfo
	req.OrderAmount = orderAmount
	req.RefundAmount = RefundAmount
	req.Currency = currency
	reqURL := "https://www.megaezgo.com/wxapi/api/WeiXin"
	sdk := NewSDK(apiStoreId,terminalIp,reqURL,apiStorePw,privateKey)
	rsp = new(RefundRsp)
	_, err = sdk.RefundJsonExcute("Refund",req, rsp)
	if err != nil {
		beego.Debug("Megaezgo Refunds err:", err.Error())
		return
	}
	return
}

